//
//  InputTef.swift
//  OnemeetingDemo
//
//  Created by zhangheng on 2020/2/10.
//  Copyright © 2020 www.onemeeting.1meetingIos. All rights reserved.
//

import Foundation

class InputTef: NSView {
    
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        self.setupUI()
    }
    
    required init?(coder decoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    var isSelect:Bool = false {
        didSet {
            let borderColor = isSelect ? color_main140:color_gray(200)
            let selectColor = isSelect ? color_rgba(r: 220, g: 235, b: 255):NSColor.clear
            self.selectView.layer?.backgroundColor = selectColor.cgColor
            self.bgLineView.zh_addBorder(radius: 10, borderColor: borderColor, borderWidth: 0.5)
        }
    }
    
    
    func setupUI() {
        self.addSubview(selectView)
        selectView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        self.addSubview(bgLineView)
        bgLineView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(NSEdgeInsetsMake(3, 3, 3, 3))
        }
        
        self.addSubview(defaulTef)
        defaulTef.snp.makeConstraints { (make) in
            make.height.equalTo(20)
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.centerY.equalToSuperview()
        }
    }
    
    lazy var bgLineView: NSView = {
        let view = NSView()
        view.wantsLayer = true
        view.layer?.backgroundColor = NSColor.white.cgColor
        view.zh_addBorder(radius: 10, borderColor: color_gray(200), borderWidth:0.5 )
        return view
    }()
    
    lazy var selectView: NSView = {
        let view = NSView()
        view.wantsLayer = true
        view.layer?.backgroundColor = NSColor.clear.cgColor
        view.zh_addBorder(radius: 10, borderColor: nil, borderWidth: 0)
        return view
    }()
    
    
    lazy var defaulTef: BaseTextField = {
        let tef = BaseTextField()
        tef.wantsLayer = true
        tef.isBordered = false
        tef.backgroundColor = NSColor.clear
        tef.focusRingType = NSFocusRingType.none
        tef.cell = defaultTefCell
        tef.placeholderString = "请输入.."
        tef.maximumNumberOfLines = 1
        //tef.drawsBackground = true
        //tef.isBordered = true
        //tef.isBezeled = true
        return tef
    }()
    
    lazy var defaultTefCell: VerCenteredTeFCell = {
        let cell = VerCenteredTeFCell()
        cell.isEditable = true
        cell.title = ""
        cell.textColor = color_gray(40)
        cell.font = NSFont.systemFont(ofSize: 16)
        cell.sendsActionOnEndEditing = true
        return cell
    }()
}
